package com.nwpu.server.learning.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.nacos.api.utils.StringUtils;
import com.nwpu.server.common.response.PageUtils;
import com.nwpu.server.common.response.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nwpu.server.learning.dao.AlgorithmDao;
import com.nwpu.server.learning.entity.AlgorithmEntity;
import com.nwpu.server.learning.service.AlgorithmService;


@Service("algorithmService")
public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmDao, AlgorithmEntity> implements AlgorithmService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AlgorithmEntity> page = this.page(
                new Query<AlgorithmEntity>().getPage(params),
                new QueryWrapper<AlgorithmEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<String> listName(String name) {
        name = StringUtils.trim(name);
        if (ObjectUtil.isNotNull(name)) {
            return baseMapper.listName(name);
        } else {
            return baseMapper.listAll();
        }
    }

}